def process_image(img, display=False):
img = camera.undistort(img)
threshold = Threshold()
combined_binary = threshold.get_threshold(img)
threshold.display(img, display)
perspective = Perspective()
warped = perspective.warp_image(combined_binary, perspective.perspective_transform())
perspective.display(img, warped, display)
line = Line();
line.detect_initial_lane_lines(warped, display)
line.detect_subsequent_lane_lines(warped)
line.measure_curvature(warped, display)
newwarp = line.identify_lane_area(warped)
return generate_output(img, line, newwarp)
def generate_output(img, line, newwarp):
font = cv2.FONT_HERSHEY_PLAIN
cv2.putText(img,'Left curve' + ' ' + str(line.left_curverad)[:6] + 'm',(10,30), font, 1,(255,255,255),2)
cv2.putText(img,'Right curve' + ' ' + str(line.right_curverad)[:6] + 'm',(10,60), font, 1,(255,255,255),2)
distance_from_center = abs((640 - line.position)*3.7/700)
if line.position > 640:
cv2.putText(img, 'Position is {:.2f}m left of center'.format(distance_from_center), (10,90), font, 1, color=(255,255,255), thickness = 2)
else:
cv2.putText(img, 'Position is {:.2f}m right of center'.format(distance_from_center), (10,90), font, 1, color=(255,255,255), thickness = 2)
# Combine the result with the original image
return cv2.addWeighted(img, 1, newwarp, 0.3, 0)
def process_test_images():
images = glob.glob('test_images/*.jpg')
for fname in images:
img = mpimg.imread(fname)
result = process_image(img, True)
plt.figure()
plt.imshow(result)
process_test_images()